package com.dgut.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.stp.StpUtil;
import com.dgut.common.ExamineState;
import com.dgut.common.SelectRole;
import com.dgut.pojo.receive.ReceiveId;
import com.dgut.service.*;
import com.dgut.utils.PageRequestInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.concurrent.ConcurrentHashMap;

@CrossOrigin
@SuppressWarnings({"all"})
@RestController
@Api("AdministratorController")
@RequestMapping("/AdministratorController")
public class AdministratorController {
    @Resource
    private AdministratorService administratorService;
    @Resource
    private UserService userService;
    @Resource
    private OrderEvaluationService orderEvaluationService;
    @Resource
    private BuyerService buyerService;
    @Resource
    private OrderFlagService orderFlagService;
    @Resource
    private ProcessVoucherService processVoucherService;
    /**
     * start-zwb
     */
    /**
     * end-zwb
     */


    /**
     * start-gxd
     */

    @ApiOperation("分页获取采买方用户，返回BuyerList")
    @PostMapping("/getBuyerByPage")
    public Object getBuyerByPage(@ApiParam(value = "需要PageNum和PageSize的封装对象")
                                           @RequestBody PageRequestInfo pageRequestInfo){
        return buyerService.getBuyerByPage(pageRequestInfo);
    }

    @ApiOperation("采买方用户模糊查询，返回Buyer")
    @GetMapping("/selectBuyerByName")
    public Object selectBuyerByName(@ApiParam(value = "用户名称",required = false)
                                                  @RequestParam(required = false) String name){
        return buyerService.selectBuyerListByName(name);
    }

    @ApiOperation("根据id查询采买方用户，返回Buyer")
    @GetMapping("/selectBuyerById")
    public Object selectBuyerById(@ApiParam(value = "用户id",required = true)
                                                     @RequestParam(required = true) int id){
        return buyerService.selectBuyerById1(id);
    }

    @ApiOperation("冻结采买方用户")
    @PostMapping("/blockBuyer")
    public Object blockBuyer(@ApiParam(value = "用户id",required = true)
                                            @RequestParam(required = true) int id){
        return administratorService.blockBuyer(id);
    }

    @ApiOperation("解冻采买方用户")
    @PostMapping("/unBlockBuyer")
    public Object unBlockBuyer(@ApiParam(value = "用户id",required = true)
                            @RequestParam(required = true) int id){
        return administratorService.unBlockBuyer(id);
    }

    @ApiOperation("分页获取待指派的订单，返回OrderList")
    @PostMapping("/getWaitAssignedOrder")
    public Object getWaitAssignedOrder(@ApiParam(value = "需要PageNum和PageSize的封装对象")
                                 @RequestBody PageRequestInfo pageRequestInfo){
        return orderFlagService.getWaitAssignedOrder(pageRequestInfo);
    }

    @ApiOperation("分页获取待审核的订单，返回OrderList")
    @PostMapping("/getWaitReviewOrder")
    public Object getWaitReviewOrder(@ApiParam(value = "需要PageNum和PageSize的封装对象")
                                       @RequestBody PageRequestInfo pageRequestInfo){
        return orderFlagService.getWaitReviewOrder(pageRequestInfo);
    }

    @ApiOperation("分页获取'取消中'的订单，返回OrderList")
    @PostMapping("/getCancelingOrder")
    public Object getCancelingOrder(@ApiParam(value = "需要PageNum和PageSize的封装对象")
                                     @RequestBody PageRequestInfo pageRequestInfo){
        return orderFlagService.getCancelingOrder(pageRequestInfo);
    }

    @ApiOperation("分页获取全部订单，返回OrderList")
    @PostMapping("/getAllOrder")
    public Object getAllOrder(@ApiParam(value = "需要PageNum和PageSize的封装对象")
                                    @RequestBody PageRequestInfo pageRequestInfo){
        return orderFlagService.getAllOrder(pageRequestInfo);
    }

    /**
     * end-gxd
     */


    /**
     * start-lzh
     */
    @ApiOperation(value = "订单指派",notes = "")
    @GetMapping("/assignOrder")
    public Object assignOrder(@ApiParam(value = "传订单的id和服务商的id",required = true)
                              @RequestParam Integer orderId,
                              @RequestParam Integer serviceId){
        return orderFlagService.assignOrder(orderId,serviceId);
    }

    @ApiOperation(value = "订单审核",notes = "")
    @GetMapping("/reviewOrder")
    public Object reviewOrder(@ApiParam(value = "传订单的id和是否通过字段",required = true)
                              @RequestParam Integer orderId,
                              @RequestParam String agreeOrNot){
        return orderFlagService.reviewOrder(orderId,agreeOrNot);
    }

    @ApiOperation(value = "取消订单",notes = "")
    @GetMapping("/cancelOrder")
    public Object cancelOrder(@ApiParam(value = "传订单的id",required = true)
                              @RequestParam Integer orderId){
        return orderFlagService.cancelOrder(orderId);
    }
    @ApiOperation(value = "根据订单id获取订单的凭证",notes = "")
    @GetMapping("/selectProcessVoucherByOrderId")
    public Object selectProcessVoucherByOrderId(@ApiParam(value = "传订单的id",required = true)
                                                @RequestParam Integer orderId){
        return processVoucherService.selectProcessVoucherByOrderId(orderId);
    }

    /**
     * end-lzh
     */

    /**
     * start-hwf
     */
    @ApiOperation("获取通过审核的服务评价列表")
    @PostMapping("/getSuccessOrderEvaluation")
    public Object getSuccessOrderEvaluation(@ApiParam(value = "分页信息",required = true) PageRequestInfo pageRequestInfo){
        ConcurrentHashMap resultMap = new ConcurrentHashMap();
        resultMap.put("successOrderEvaluationPage",orderEvaluationService.getSuccessOrderEvaluation(pageRequestInfo));
        return resultMap;
    }
    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation("获取未通过审核的服务评价列表")
    @PostMapping("/getFailOrderEvaluation")
    public Object getFailOrderEvaluation(@ApiParam(value = "分页信息",required = true) PageRequestInfo pageRequestInfo){
        ConcurrentHashMap resultMap = new ConcurrentHashMap();
        resultMap.put("failOrderEvaluationPage",orderEvaluationService.getFailOrderEvaluation(pageRequestInfo));
        return resultMap;
    }
    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation("获取未审核的服务评价列表")
    @PostMapping("/getUnapprovedOrderEvaluation")
    public Object getUnapprovedOrderEvaluation(@ApiParam(value = "分页信息",required = true) PageRequestInfo pageRequestInfo){
        ConcurrentHashMap resultMap = new ConcurrentHashMap();
        resultMap.put("unapprovedOrderEvaluationPage",orderEvaluationService.getUnapprovedOrderEvaluation(pageRequestInfo));
        return resultMap;
    }

    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation("通过服务评价审核")
    @PostMapping("/passOrderEvaluation")
    public Object passOrderEvaluation(@ApiParam(value = "服务评价id",required = true) ReceiveId receiveId){
        ConcurrentHashMap resultMap = new ConcurrentHashMap();
        if(orderEvaluationService.changeStateOrderEvaluation(receiveId.getId(), ExamineState.SUCCESS)){
            resultMap.put("result",true);
            resultMap.put("message","设置成功！");
        }else{
            resultMap.put("result",false);
            resultMap.put("message","设置失败！");
        }
        return resultMap;
    }

    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation("不通过服务评价审核")
    @PostMapping("/noPassOrderEvaluation")
    public Object noPassOrderEvaluation(@ApiParam(value = "服务评价id",required = true) ReceiveId receiveId){
        ConcurrentHashMap resultMap = new ConcurrentHashMap();
        if(orderEvaluationService.changeStateOrderEvaluation(receiveId.getId(), ExamineState.FAIL)){
            resultMap.put("result",true);
            resultMap.put("message","设置成功！");
        }else{
            resultMap.put("result",false);
            resultMap.put("message","设置失败！");
        }
        return resultMap;
    }

    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation("撤销服务评价审核")
    @PostMapping("/revocationOrderEvaluation")
    public Object revocationOrderEvaluation(@ApiParam(value = "服务评价id",required = true) ReceiveId receiveId){
        ConcurrentHashMap resultMap = new ConcurrentHashMap();
        if(orderEvaluationService.changeStateOrderEvaluation(receiveId.getId(), ExamineState.NOT_APPROVED)){
            resultMap.put("result",true);
            resultMap.put("message","设置成功！");
        }else{
            resultMap.put("result",false);
            resultMap.put("message","设置失败！");
        }
        return resultMap;
    }

    /**
     * end-hwf
     */
}
